package com.aaa.system.controller;


import com.aaa.system.entity.Role;
import com.aaa.system.entity.UserRole;
import com.aaa.system.service.IRoleService;
import com.aaa.system.service.IUserRoleService;
import com.aaa.system.vo.Result;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 闫克起
 * @since 2023-06-20
 */
@RestController
@RequestMapping("/system/role")
public class RoleController {

    @Autowired
    private IRoleService roleService;
    @Autowired
    private IUserRoleService userRoleService;

    @GetMapping("fenRole")
    public Result fenRole(String userId){
          //1.查询所有的角色
        List<Role> list = roleService.list();
        //2.根据id查询用户具有的角色id
        QueryWrapper<UserRole> wrapper=new QueryWrapper<>();
        wrapper.eq("user_id",userId);
        List<String> roleIds = userRoleService.list(wrapper).stream().map(item -> item.getRoleId()).collect(Collectors.toList());

        Map<String,Object> map=new HashMap<>();
        map.put("list",list);
        map.put("roleIds",roleIds);
        return new Result(200,"查询成功",map);
    }
}
